package org.reliablesource.prism.ui.workbench.actions;

/**
 *
 *  Copyright (c) 2006, Reliable Source, Inc. All Rights Reserved
 *
 *	Created on: Mar 11, 2006
 *	@author Dennis Park <a href="mailto:dennis.park@gmail.com">dennis.park@gmail.com</a>
 *
 */

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
import org.reliablesource.prism.ui.popup.actions.SavePrismElementAction;

public class SaveElementAction implements IObjectActionDelegate {
	
	public static String ID = "IPrismScreen.Contribution.SaveElementAction";

	SavePrismElementAction saveAction;
	IWorkbenchPart currentPart;
	
	public SaveElementAction(){
		saveAction = new SavePrismElementAction();
	}

	public void setActivePart(final IAction _action, final IWorkbenchPart _targetPart) {
		currentPart = _targetPart;
		if(_action == null) 
			return;
		
		if(_action.getImageDescriptor() == null)
			_action.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
	}

	public void run(final IAction _action) {
		
		if(!_action.isEnabled())
			return;

		saveAction.run();
	}
	
	public void selectionChanged(IAction _action, ISelection _selection) {

		_action.setEnabled(false);
		
		if(null == _selection)
				return;
			
		_action.setEnabled(saveAction.setSelection(_selection));
	}

	public String getId() {
		return ID;
	}
}
